<template>
  <view class="pc-config-wizard">
    <!-- 步骤条 -->
    <view class="steps-container"  v-if="steps.length>0">
      <view 
        v-for="(step, index) in steps" 
        :key="index"
        class="step-item"
        @click="currentStep = index"
        :class="{
          'active': currentStep === index,
          'completed': step.status === true,
          'error': step.status === false,
        }"
      >
        <view class="step-icon">
          <text v-if="step.status === true" class="icon-success">✓</text>
          <text v-else-if="step.status === false" class="icon-error">!</text>
          <text v-else class="icon-pending">{{ index + 1 }}</text>
        </view>
        <view class="step-name">{{ step.name }}</view>
        <view class="step-line" v-if="index < steps.length - 1"></view>
      </view>
    </view>

    <!-- 步骤内容区域 -->
    <view class="content-container" v-if="steps.length>0">
      <view class="step-content">
        <view class="step-header">
          <h2 class="step-title">{{ currentStepData.name }}</h2>
          <view class="step-status" :class="currentStepData.status">
            {{ currentStepData.status ?'配置完成' :'未配置' }}
          </view>
        </view>
        
        <view class="step-hint">{{ currentStepData.hint }}</view>
        
        <!-- 错误提示 -->
        <view class="error-message" v-if="currentStepData.errorMsg">
          <text class="error-icon">⚠</text>
          {{ currentStepData.errorMsg }}
        </view>

        <!-- 成功提示 -->
        <view class="success-message" v-if="currentStepData.status === true">
          <text class="success-icon">✓</text>
          配置成功
        </view>

        <!-- 操作说明 -->
        <view class="operation-guide">
          <view class="guide-title">操作指引：</view>
          <view class="guide-content">
            <text class="guide-text">{{ currentStepData.guide }}</text>
          </view>
        </view>
      </view>
    </view>

    <!-- 操作按钮 -->
    <view class="action-buttons"  v-if="steps.length>0">
      <button 
        class="btn next-btn" 
        :loading="loading"
        @click="check(currentStepData.method_name)"
      >
        检查{{currentStepData.name}}配置
      </button>
    </view>
  </view>
</template>

<script>
export default {
	data() {
		return {
			currentStep: 0,
			loading: false,
			steps: []
		}
	},
  
	computed: {
		currentStepData() {
			return this.steps[this.currentStep]
		}
	},

	onLoad(res) {

		if(res.firm_id){
			this.$common.SetFirmId(res.firm_id)
			this.check('GetSteps')

		}else if(res.appid){
			this.$common.SetFirmId(res.appid)
			this.check('GetSteps')
		}
	},
	methods: {
		check(method_name) {
			var that = this
			that.$common.get_request(
				{
					type: 'check',
					method_name:method_name
				},
				(res)=>{
					if(method_name == 'GetSteps'){
						
						that.steps = res.data
						
						return
					}
					const list = that.steps;
					
					for(var i=0; i<list.length; i++){
						if(list[i].method_name == method_name){
							that.steps[i].status = res.status
							that.$set(that.steps, i, that.steps[i])
							break;
						}
					}
				}
			);
		},

  }
}
</script>

<style scoped>
.pc-config-wizard {
  width: 1000px;
  margin: 20px auto;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  padding: 30px;
  max-height: 95vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

/* 步骤条样式 - 修复对齐问题 */
.steps-container {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 30px;
  position: relative;
  flex-shrink: 0;
  width: 100%;
}

.step-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 2;
  cursor: pointer;
  transition: all 0.3s ease;
  flex: 1;
  min-width: 0;
  padding: 0 5px;
}

.step-item:hover {
  transform: translateY(-2px);
}

.step-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 8px;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

/* 步骤图标状态样式 */
.step-item.pending .step-icon {
  background: #e0e0e0;
  color: #999;
  border: 2px solid #e0e0e0;
}

.step-item.active .step-icon {
  background: white;
  color: #1890ff;
  border: 2px solid #1890ff;
  transform: scale(1.1);
  box-shadow: 0 2px 8px rgba(24, 144, 255, 0.3);
}

.step-item.completed .step-icon {
  background: #52c41a;
  color: white;
  border: 2px solid #52c41a;
}

.step-item.error .step-icon {
  background: #ff4d4f;
  color: white;
  border: 2px solid #ff4d4f;
}

/* 图标特殊样式 */
.icon-success, .icon-error {
  font-weight: bold;
}

.step-name {
  font-size: 13px;
  color: #666;
  font-weight: 500;
  text-align: center;
  transition: all 0.3s ease;
  line-height: 1.4;
  word-break: break-all;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  max-height: 36px;
  width: 100%;
}

/* 步骤名称状态样式 */
.step-item.active .step-name {
  color: #1890ff;
  font-weight: 600;
}

.step-item.completed .step-name {
  color: #52c41a;
}

.step-item.error .step-name {
  color: #ff4d4f;
}

/* 步骤连接线 - 统一颜色 */
.step-line {
  position: absolute;
  top: 16px;
  left: calc(50% + 16px);
  right: calc(-50% + 16px);
  height: 2px;
  background: #e0e0e0; /* 统一为灰色 */
  z-index: -1;
}

/* 内容区域样式 */
.content-container {
  flex: 1;
  min-height: 0;
  margin-bottom: 30px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.step-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 10px;
}

.step-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-shrink: 0;
}

.step-title {
  font-size: 22px;
  font-weight: 600;
  color: #333;
  margin: 0;
  flex: 1;
}

.step-status {
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}



.step-status.success {
  background: #f6ffed;
  color: #52c41a;
  border: 1px solid #b7eb8f;
}

.step-status.error {
  background: #fff2f0;
  color: #ff4d4f;
  border: 1px solid #ffccc7;
}

.step-hint {
  font-size: 14px;
  color: #666;
  line-height: 1.6;
  margin-bottom: 20px;
  flex-shrink: 0;
  background: #f8f9fa;
  padding: 15px;
  border-radius: 8px;
  border-left: 4px solid #e1e1e1;
}

/* 操作指引样式 */
.operation-guide {
  background: #f0f7ff;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 20px;
  border-left: 4px solid #1890ff;
  flex-shrink: 0;
}

.guide-title {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  margin-bottom: 8px;
}

.guide-content {
  font-size: 14px;
  color: #666;
  line-height: 1.5;
}

.guide-text {
  color: #1890ff;
  font-weight: 500;
}

/* 消息提示样式 */
.error-message {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #fff2f0;
  border: 1px solid #ffccc7;
  border-radius: 8px;
  color: #ff4d4f;
  font-size: 14px;
  margin-bottom: 20px;
  flex-shrink: 0;
}

.success-message {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #f6ffed;
  border: 1px solid #b7eb8f;
  border-radius: 8px;
  color: #52c41a;
  font-size: 14px;
  margin-bottom: 20px;
  flex-shrink: 0;
}

.error-icon, .success-icon {
  font-weight: bold;
}

/* 按钮样式 */
.action-buttons {
  display: flex;
  justify-content: center;
  margin-top: 20px;
  flex-shrink: 0;
}

.btn {
  min-width: 140px;
  height: 44px;
  border-radius: 6px;
  font-size: 16px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.next-btn {
  background: #1890ff;
  color: #fff;
}

.next-btn:hover {
  background: #40a9ff;
}

.next-btn:active {
  background: #096dd9;
}

.next-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* 响应式调整 */
@media (max-width: 1100px) {
  .pc-config-wizard {
    width: 95%;
    margin: 10px auto;
    padding: 20px;
  }
  
  .step-name {
    font-size: 12px;
  }
  
  .step-icon {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }
  
  .step-line {
    top: 14px;
  }
}
</style>